﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
//引入命名空间
using stwh_Model;
using stwh_BLL;
using stwh_Common;
using Newtonsoft.Json;
using System.Web.SessionState;
using stwh_Web.Handler.stwh_admin;

namespace stwh_Web.Handler.extend.huodong
{
    /// <summary>
    /// register 的摘要说明
    /// </summary>
    public class register : IHttpHandler, IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            try
            {
                if (context.Request.HttpMethod.ToLower() == "post")
                {
                    #region 检测注册时间
                    try
                    {
                        INIFile inifile = new INIFile(System.Web.HttpRuntime.AppDomainAppPath + "config/activity.ini");
                        string stoptime = inifile.IniReadValue("activity", "key");
                        if (DateTime.Now > DateTime.Parse(stoptime))
                        {
                            BaseHandler.SendResponseMsgs(context, "-1", "活动已经截止参与，请关注抽奖结果！", 0);
                            return;
                        }
                    }
                    catch (Exception)
                    {
                        BaseHandler.SendResponseMsgs(context, "-1", "活动未设置注册截止时间，请联系主办方！", 0);
                        return;
                    }
                    #endregion
                    string name = context.Request["name"];
                    string mobile = context.Request["mobile"];
                    if (!PageValidate.IsNumber(mobile) || mobile.Length!=11)
                    {
                        BaseHandler.SendResponseMsgs(context, "-1", "手机号码格式错误！", 0);
                        return;
                    }
                    stwh_cjtel model = new stwh_cjtel();
                    model.stwh_cjaddtime = DateTime.Now;
                    model.stwh_cjname = name;
                    model.stwh_cjmobile = mobile;
                    if (new stwh_cjtelBLL().Add(model) > 0)
                    {
                        BaseHandler.SendResponseMsgs(context, "0", "ok", 0);//注册成功
                    }
                    else
                    {
                        BaseHandler.SendResponseMsgs(context, "-1", "no", 0);//注册失败
                    }
                }
                else
                {
                    BaseHandler.SendResponseMsgs(context, "-1", "数据传输方法错误，请采用post方式！", 0);
                }
            }
            catch (Exception)
            {
                BaseHandler.SendResponseMsgs(context, "-1", "服务器异常，请稍后再试！", 0);
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}